package com.example.demo.domain.system.user;

import com.example.demo.response.CustomRspBody;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/system/user")
@Api(tags="SysUserController",value = "用户管理")
public class SysUserController {
    @Autowired
    private SysUserService sysUserService;

    @ApiOperation(value = "/findPage", notes = "分页查询用户",httpMethod = "GET")
    @GetMapping("/findPage")
    public CustomRspBody findByWhere(
            @RequestParam(required = false, defaultValue = "0") int page,
            @RequestParam(required = false, defaultValue = "20") int size,
            @RequestParam(required = false, defaultValue = "lastLoginDate") String dir,
            @RequestParam(required = false, defaultValue = "ASC") Sort.Direction sort,
            @RequestParam(required = false, defaultValue = "") String searchInfo
    ){
        return sysUserService.findByWhere(PageRequest.of(page,size,sort,dir), searchInfo);
    }
    @ApiOperation(value = "/findList", notes = "查询用户列表",httpMethod = "GET")
    @GetMapping("/findList")
    public CustomRspBody findList(@RequestBody Map<String,Object> params){
        return sysUserService.findByWhere(params);
    }
    @ApiOperation(value="/addUser", notes = "添加用户", httpMethod = "POST")
    @PostMapping("/addUser")
    public CustomRspBody addUser(@RequestBody SysUserEntity sysUserEntity) {
        return sysUserService.addUser(sysUserEntity);
    }
}
